package com.smxy.hunzi.user.valid.constraintvalidator;

import com.smxy.hunzi.user.valid.validannotation.SexValid;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/**
 * @author 李涛
 * @date 2020-07-10 19:12
 */
public class SexConstraintValidator implements ConstraintValidator<SexValid,String> {
    private Set<String> set = new HashSet<>();
    @Override
    public void initialize(SexValid constraintAnnotation) {
        Collections.addAll(set, constraintAnnotation.vals());
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        return set.contains(value);
    }
}
